<template>
  <div>
    <h2>{{article.articleTitle}}</h2>
    <div>{{article.articleContent}}</div>
  </div>

  <div class="option">
    <el-button class="btn" @click="back" round>返回</el-button>
    <el-button
        v-if="user.role == 2 && article.statusId == 1" class="btn"
        @click="option('toAdopt')"
        round>通过</el-button>
    <el-button
        v-if="user.role == 2 && article.statusId == 1" class="btn"
        @click="option('toFail')"
        round>驳回(不通过)</el-button>
    <el-button
        v-if="user.role == 2 && article.statusId == 3" class="btn"
        @click="option('release')"
        round>发布</el-button>
    <el-button
        v-if="user.role == 2 && article.statusId == 4" class="btn"
        @click="option('withdraw')"
        round>撤销</el-button>
  </div>
</template>

<script>
import {ElMessage} from "element-plus";

export default {
  name: "ArticlePage",
  inject:['reload'],
  mounted() {
    this.A();
  },

  data(){
    return{
      article:"",
      user:JSON.parse(window.sessionStorage.getItem('user'))
    }
  },

  methods:{
    A(){
      // console.log(this.$route.params.articleId)
      let that = this;
      this.$axios.get('/articles/queryById', {
            params: { "id": this.$route.params.articleId }
          }).then(function (response) {
            // console.log(response)
            that.article = response.data;
            }).catch(function (error) {
        alert(error);
      });
    },

    back(){
      this.$router.go(-1)
      // console.log(11)
      this.reload;
    },

    option(url){
      this.$confirm('是否确认操作?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let that = this;
        this.$axios({
          method: "put",
          url:"/upStatus/"+ url +"?articleId=" + this.article.articleId,
        }).then(function (response) {
          console.log(response);
          if(response.data.code == 2) {
            ElMessage.error(response.data.msg);
          }else {
            ElMessage.success({
              message: response.data.msg,
              type: 'success'
            });
            that.back();

          }
        }).catch(function (error) {
          console.log(error);
          ElMessage.error(error.message);
        });

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
  },



}
</script>

<style scoped>

.btn {
  position: relative;
  left: 30%;
  margin-top: 10px;
  /*width: 100px;*/
  height: 38px;
}

</style>